//
//  ManagerViewController.m
//  EasyToTesco
//
//  Created by mc on 16/3/21.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "ManagerViewController.h"
#import "HeaderFileForEasyToTesco.h"
#import "OrderDetailTableViewCell.h"

#import "ShowOnlyViewController.h"

//添加新地址
#import "AddAddressViewController.h"



@interface ManagerViewController ()<UITableViewDataSource, UITableViewDelegate>;

@property (nonatomic, strong)UITableView *managertableview;

@end

@implementation ManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self addmanagertopUI];
    
    [self addmanagertableviewUI];
    
}

- (void)addmanagertopUI {
    
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, (self.secondView.frame.size.height-20)/2, 20, 20)];
    image1.image = [UIImage imageNamed:@"goback-icon.png"];
    [self.secondView addSubview:image1];
    self.leftBtn.hidden = YES;
    
    UIButton *goBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    goBackBtn.frame = CGRectMake(0, 0, self.secondView.frame.size.height, self.secondView.frame.size.height);
    [goBackBtn addTarget:self action:@selector(gobackClick) forControlEvents:UIControlEventTouchUpInside];
    [self.secondView addSubview:goBackBtn];
    self.titleLabel.text = @"管理收货地址";
    
    UIView *lastView = [[UIView alloc] initWithFrame:CGRectMake(0, HIGHT-60, WEITH, 60)];
    lastView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lastView];
    
    UIButton *addbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    addbtn.frame = CGRectMake((WEITH-80)/2, 10, 160, 40);
    addbtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [addbtn setTitle:@"添加收货地址" forState:UIControlStateNormal];
    [addbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [addbtn addTarget:self action:@selector(addBtnclick) forControlEvents:UIControlEventTouchUpInside];
    addbtn.backgroundColor = [UIColor greenColor];
    [lastView addSubview:addbtn];
    

}

- (void)addBtnclick {
    //添加收货地址
    AddAddressViewController *addVC = [[AddAddressViewController alloc] init];
    [self presentViewController:addVC animated:YES completion:nil];
}


- (void)gobackClick {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)addmanagertableviewUI {
    self.managertableview = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.secondView.frame), WEITH, HIGHT - CGRectGetMaxY(self.secondView.frame)-60) style:UITableViewStylePlain];
    self.managertableview.dataSource = self;
    self.managertableview.delegate = self;
    self.managertableview.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.managertableview];
}

#pragma mark -- UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.manamgerArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"OrderDetailTableViewCellget";
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderDetailTableViewCell" owner:nil options:nil] lastObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    
    //    cell.orderDetailName.text
    //    cell.orderDetailPhoneNum.text
    //    cell.orderDetailAddress.text
    
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
#pragma mark -- UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
#pragma mark -- 点击cell后跳转到单个收货地址的视图
    ShowOnlyViewController *showVC = [[ShowOnlyViewController alloc] init];
    [self presentViewController:showVC animated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
